<extend name="Common@Layout:hui-admin" />
<block name="title"><title>Administator管理后台</title></block>
<block name="style">
</block>

<block name="main">
	<nav class="breadcrumb">
		<i class="Hui-iconfont"></i>
		 首页 <span class="c-gray en">&gt;</span>
		 内容管理 <span class="c-gray en">&gt;</span>  
		表格可编辑 资讯列表 
		<a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont"></i></a>
	</nav>
	
	<div class="pd-20">
		<div class="cl pd-5 bg-1 bk-gray mt-20"> 
			<div class="btn-group l">
				<a href="{:U('Datagridadmin/index',array(status=>0))}" class="btn btn-default <if condition='$_GET["status"] eq 0'>btn-primary</if> radius">全部</a>
			  	<a href="{:U('Datagridadmin/index',array(status=>1))}" class="btn btn-default <if condition='$_GET["status"] eq 1'>btn-primary</if> radius">发布</a>
			  	<a href="{:U('Datagridadmin/index',array(status=>2))}" class="btn btn-default <if condition='$_GET["status"] eq 2'>btn-primary</if> radius">草稿</a>
			</div>
			<span class="l ml-20"> 
				<a href="javascript:;" class="btn btn-danger radius ajax-post confirm" target-form="mini-form" data-msg="确定批量删除？" data-url="{:U('Articles/del')}"><i class="Hui-iconfont"></i> 批量删除</a> 
				<a class="btn btn-primary radius" href="javascript:;" onclick="open_iframe_dialog('{:U('articles/edit')}','创建文章',['100%','100%'],1)"><i class="Hui-iconfont"></i> 添加文章</a> 
			</span> 
		</div>
		<php>
			$result = _get_list_data(U('Datagridadmin/index'),$_GET,$map,D('Datagrid'));
		</php>
		<form class="mini-form">
		<table id="datagrid" class="table table-border table-bordered table-bg table-hover table-sort">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th width="80">ID</th>
					<th>data1</th>
					<th>data2</th>
					<th>data3</th>
					<th width="120">更新时间</th>
					<th width="120">操作</th>
				</tr>
			</thead>
			<tbody>
				<foreach name="result['data']['list']" item="vo">
				<tr class="text-c" data-trid="{$vo.id}">
					<td><input type="checkbox" value="{$vo['id']}" name="ids[]"></td>
					<td>{$vo.id}</td>
					<td class="editbox" data-dt="data1">{$vo.data1}</td>
					<td class="editbox" data-dt="data2" data-type="textarea">{$vo.data2}</td>
					<td>{$vo.data3}</td>
					<td>{$vo.create_time}</td>
					<td class="f-14 td-manage">
            			<a style="text-decoration:none" class="ml-5 mini_del" data-url="{:U('articles/del','ids='.$vo['id'])}" href="javascript:;" title="删除"><i class="Hui-iconfont"></i></a>
					</td>
				</tr>
				</foreach>
			</tbody>
		</table>
		</form>
		{$result['pagetpl']}
	</div>
	
	
</block>

<block name="script">
<script>
$("#datagrid td").on('click',function(){
	// 获取被点击的td  
    var $td = $(this);
	// 检测此td是否是可编辑的
	if(!$td.hasClass('editbox')){
		return false;
	}
    // 检测此td是否已经被替换了，如果被替换直接返回  
    if ($td.children("input").length > 0) {  
        return false;  
    } 
    // 获取$td中的文本内容  
    var text = $td.text();
    var tddt = $td.attr("data-dt");
    var id = $td.parent().attr("data-trid");
    var type = $td.attr("data-type");
    
    var $input;
    if(type == "textarea"){
    	$input = $("<textarea class='textarea'></textarea>")
    	$input.text(text);
    }else{
    	// 创建替换的input 对象  
        $input = $("<input type='text' class='input-text'>");  
        // 设置value值  
        $input.val(text);  
        $input.attr("name",tddt);
    }
 	
  
 	// 清除td中的文本内容  
    $td.html("");  
    $td.append($input);
    //console.log("aa1");
    $input.focus();
    
    $input.blur(function(){
		var newtext = $input.val();
		if(text != newtext){
			var data = {
				"id" : id,
				"dname" : tddt,
				"dvalue" : newtext
			};
			$.post("/Material/Datagridadmin/savedata",data);
		}
		$td.html(newtext);
	})
    
});

</script>
</block>